﻿
Namespace Compiler.Semantic
    Public Class TypeDeclBinder
        Inherits Binder

        Private m_symbol As Symbol
        Public Property Symbol() As Symbol
            Get
                Return m_symbol
            End Get
            Set(ByVal value As Symbol)
                m_symbol = value
            End Set
        End Property

        Private m_typeParamCount As Integer
        Public Property TypeParameterCount() As Integer
            Get
                Return m_typeParamCount
            End Get
            Set(ByVal value As Integer)
                m_typeParamCount = value
            End Set
        End Property

        Public Sub New(ByVal symbol As Symbol, Optional ByVal typeParamCount As Integer = 0)
            m_symbol = symbol
            m_typeParamCount = typeParamCount
        End Sub

        Public Overrides Function Equals(ByVal other As Binder) As Boolean
            If other Is Nothing Then Return False
            If Not TypeOf other Is TypeDeclBinder Then Return False

            Dim typedOther As TypeDeclBinder = TryCast(other, TypeDeclBinder)

            If typedOther.m_symbol.Equals(m_symbol) AndAlso typedOther.m_typeParamCount = m_typeParamCount Then
                Return True
            Else
                Return False
            End If
        End Function

        Public Overrides Function GetHashCode() As Integer
            Dim rnd As New Random(m_typeParamCount + 1)
            Return m_symbol.GetHashCode() Xor rnd.Next()
        End Function
    End Class
End Namespace